﻿
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using System.ComponentModel.DataAnnotations;
using WalkingTec.Mvvm.Core;
using WalkingTec.Mvvm.Core.Extensions;
using Digitalmes.Model.EquipmentManagement;
using Digitalmes.Model;



namespace Digitalmes.ViewModel.EquipmentManagement.EquipmentTagVMs
{
    public partial class EquipmentTagEquipmentDetailListVM : BasePagedListVM<EquipmentTag, EquipmentTagDetailSearcher>
    {
        
        protected override List<GridAction> InitGridAction()
        {
            return new List<GridAction>
            {
                this.MakeStandardAction("EquipmentTag", GridActionStandardTypesEnum.AddRow, "新建","", dialogWidth: 800),
                this.MakeStandardAction("EquipmentTag", GridActionStandardTypesEnum.RemoveRow, "删除","", dialogWidth: 800),
            };
        }
 
        protected override IEnumerable<IGridColumn<EquipmentTag>> InitGridHeader()
        {
            return new List<GridColumn<EquipmentTag>>{
                
                this.MakeGridHeader(x => x.TagName).SetEditType(EditTypeEnum.TextBox).SetTitle(@Localizer["Page.变量名称"].Value),
                this.MakeGridHeader(x => x.Description).SetEditType(EditTypeEnum.TextBox).SetTitle(@Localizer["Page.描述"].Value),
                this.MakeGridHeader(x => x.Address).SetEditType(EditTypeEnum.TextBox).SetTitle(@Localizer["_Admin.Address"].Value),
                this.MakeGridHeader(x => x.TagType).SetEditType(EditTypeEnum.ComboBox,typeof(TagDefineEnum).ToListItems(null,true)).SetTitle(@Localizer["Page.变量类型"].Value),
                this.MakeGridHeader(x => x.DataType).SetEditType(EditTypeEnum.ComboBox,typeof(TagDataTypeEnum).ToListItems(null,true)).SetTitle(@Localizer["Page.数据类型"].Value),
                this.MakeGridHeader(x => x.ScanRate).SetEditType(EditTypeEnum.TextBox).SetTitle(@Localizer["Page.扫描速率"].Value),
                this.MakeGridHeader(x => x.GroupType).SetEditType(EditTypeEnum.ComboBox,typeof(TagGroupEnum).ToListItems(null,true)).SetTitle(@Localizer["Page.信号组"].Value),
                this.MakeGridHeader(x => x.AccessMode).SetEditType(EditTypeEnum.ComboBox,typeof(TagAccessModeEnum).ToListItems(null,true)).SetTitle(@Localizer["Page.访问模式"].Value),
                this.MakeGridHeader(x => x.UpLimit).SetEditType(EditTypeEnum.TextBox).SetTitle(@Localizer["Page.上限"].Value),
                this.MakeGridHeader(x => x.LowerLimit).SetEditType(EditTypeEnum.TextBox).SetTitle(@Localizer["Page.下限"].Value),
                this.MakeGridHeader(x => x.Active).SetEditType(EditTypeEnum.ComboBox,Utils.GetBoolCombo(BoolComboTypes.YesNo, selectText:Wtm.Localizer?["Sys.PleaseSelect"])).SetTitle(@Localizer["Page.激活"].Value),
                this.MakeGridHeader(x => x.ActiveLimit).SetEditType(EditTypeEnum.ComboBox,Utils.GetBoolCombo(BoolComboTypes.YesNo, selectText:Wtm.Localizer?["Sys.PleaseSelect"])).SetTitle(@Localizer["Page.激活上下限"].Value),

                this.MakeGridHeaderAction(width: 200)
            };
        }

        
        public override IOrderedQueryable<EquipmentTag> GetSearchQuery()
        {
                
            var id = (long?)Searcher.EquipmentId.ConvertValue(typeof(Guid?));
            if (id == null)
                return new List<EquipmentTag>().AsQueryable().OrderBy(x => x.ID);
            var query = DC.Set<EquipmentTag>()
                .Where(x => id == x.EquipmentId)

                .OrderBy(x => x.ID);
            return query;
        }

    }

    public partial class EquipmentTagDetailSearcher : BaseSearcher
    {
        
        [Display(Name = "_Model._EquipmentTag._Equipment")]
        public string EquipmentId { get; set; }
    }

}

